From 69977dfd4cbb8608aafa8ca8b5388d4983f5430a Mon Sep 17 00:00:00 2001
From: Bas Couwenberg <sebastic@debian.org>
Date: Sat, 23 Oct 2021 17:08:31 +0200
Subject: [PATCH] Add support for proj.h, proj_api.h is removed in PROJ 8.

---
 cmake/FindPROJ4.cmake | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/cmake/FindPROJ4.cmake b/cmake/FindPROJ4.cmake
index 093deaa79..10dfc7afa 100644
--- a/cmake/FindPROJ4.cmake
+++ b/cmake/FindPROJ4.cmake
@@ -91,6 +91,21 @@ if(PROJ4_INCLUDE_DIR AND EXISTS "${PROJ4_INCLUDE_DIR}/proj_api.h")
     string(REGEX REPLACE "^.*PJ_VERSION [0-9][0-9]([0-9]).*$" "\\1" PROJ4_VERSION_PATCH "${PROJ4_H}")
     set(PROJ4_VERSION "${PROJ4_VERSION_MAJOR}.${PROJ4_VERSION_MINOR}.${PROJ4_VERSION_PATCH}")
     set(PROJ4_VERSION_COUNT 3)
+else()
+    find_path(PROJ4_INCLUDE_DIR NAMES proj.h ${_PROJ4_SEARCH} PATH_SUFFIXES include)
+    mark_as_advanced(PROJ4_INCLUDE_DIR)
+
+    if(PROJ4_INCLUDE_DIR AND EXISTS "${PROJ4_INCLUDE_DIR}/proj.h")
+        file(STRINGS "${PROJ4_INCLUDE_DIR}/proj.h" PROJ_VERSION_MAJOR REGEX "^#define PROJ_VERSION_MAJOR [0-9]+$")
+        file(STRINGS "${PROJ4_INCLUDE_DIR}/proj.h" PROJ_VERSION_MINOR REGEX "^#define PROJ_VERSION_MINOR [0-9]+$")
+        file(STRINGS "${PROJ4_INCLUDE_DIR}/proj.h" PROJ_VERSION_PATCH REGEX "^#define PROJ_VERSION_PATCH [0-9]+$")
+
+        string(REGEX REPLACE "^.*PROJ_VERSION_[A-Z]+ ([0-9]).*$" "\\1" PROJ4_VERSION_MAJOR "${PROJ_VERSION_MAJOR}")
+        string(REGEX REPLACE "^.*PROJ_VERSION_[A-Z]+ ([0-9]).*$" "\\1" PROJ4_VERSION_MINOR "${PROJ_VERSION_MINOR}")
+        string(REGEX REPLACE "^.*PROJ_VERSION_[A-Z]+ ([0-9]).*$" "\\1" PROJ4_VERSION_PATCH "${PROJ_VERSION_PATCH}")
+        set(PROJ4_VERSION "${PROJ4_VERSION_MAJOR}.${PROJ4_VERSION_MINOR}.${PROJ4_VERSION_PATCH}")
+        set(PROJ4_VERSION_COUNT 3)
+    endif()
 endif()
 
 # Allow PROJ4_LIBRARY to be set manually, as the location of the proj library
